package com.woniuxy.lab.woniu_lab.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.woniuxy.lab.woniu_lab.commons.Result;
import com.woniuxy.lab.woniu_lab.service.OrderService;
import com.woniuxy.lab.woniu_lab.service.dto.chargeDto.MyOrderDto;
import com.woniuxy.lab.woniu_lab.util.JwtUtil;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;

/**
 * <p>
 * 消费记录表 前端控制器
 * </p>
 *
 * @author Silas
 * @since 2023-03-15
 */
@RestController
@RequestMapping("/order")
@Slf4j
@Api(tags = "[G]消费记录相关接口")
@Validated
public class OrderController {

    @Resource
    private OrderService orderService;

    @ApiOperation("18 获取我的消费记录")
    @GetMapping("queryMyOrder")
    public Result<IPage<MyOrderDto>> queryMyOrder(
            @ApiParam(value = "第几页") @Min(value = 1,message = "当前页最小为1") @NotNull(message = "当前页不能为空") Integer page,
            @ApiParam(value = "每页条数") @NotNull(message = "展示数量不能为空") @Max(value = 50,message = "展示数量最大为50")
            @Min(value = 1,message = "展示数量最小为1") Integer size
    ){
        log.info("查看我的订单列表页码{},页大小{}",page,size);

        Integer userId = JwtUtil.getUserIdFromReq();
        IPage<MyOrderDto> myOrderDtoIPage = orderService.queryMyOrder(page == null?1:page,size == null?10:size,userId);

        return Result.success(200,"查询成功",myOrderDtoIPage);
    }
}

